{template 'common/header'}
 <link href="{MODULE_URL}images/weui.css" rel="stylesheet" type="text/css" />
<link href="{MODULE_URL}images/weui2.css" rel="stylesheet" type="text/css" />
<link href="{MODULE_URL}images/css/public.css" rel="stylesheet" type="text/css" />
<script src="{MODULE_URL}images/zepto.min.js"></script>
{if $op == 'edit'}
	<form action="" method="post" class="form-horizontal form" id="form">
		<div class="panel panel-default">
		<div class="panel-heading">个人信息</div>
		<div class="panel-body">
		<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">老板微信号</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[weixin]" class="form-control" value="{$business['weixin']}" />						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">老板个人一句话介绍</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[yjh]" class="form-control" value="{$business['yjh']}" />						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">老板头像</label>
					<div class="col-xs-12 col-sm-8">
						{php echo tpl_form_field_image('business[tx]', $business['tx']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">老板二维码</label>
					<div class="col-xs-12 col-sm-8">
						{php echo tpl_form_field_image('business[ewm]', $business['ewm']);}
					</div>
				</div>
			</div>
			<div class="panel-heading">商家设置</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">商户名称</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[title]" class="form-control" value="{$business['title']}" />
					</div>
				</div>

				<div>				
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">选择分类</label>
						<div class="col-sm-8 col-xs-12">
							{php echo tpl_form_field_category_2level('category', $parent, $children, $pcate, $ccate)}
						</div>
					</div>				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">店铺图片可多图</label>
					<div class="col-xs-12 col-sm-8">

						
<style>
    .uploadimg{margin: 0;padding: 0;}

    .uploadimg li{ list-style: none;width:22%;float: left; margin:5px 0 5px 4%;position: relative;}

    .uploadimg li:first-child{margin-left: 0;}

    .uploadimg li:nth-child(5n){ list-style: none;width:22%;margin:5px 0 5px 0;}

    .uploadimg img{width: 100%;}


    .upload_btn {
        background: url("{MODULE_URL}images/nmLine_bg.png") no-repeat;
        background-size: cover;
        position: relative;
        border: 2px dashed #78B0C6;
        border-radius: 5px;
        margin-top:10px;
        display:inline-block;
        margin-right:15px;
        margin-bottom: -2px;
    }
    .upload_btn.img{margin-bottom: 0;}
    .clear{clear:both;}
    .upload_btn input {
        opacity: 0;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 10;
        overflow: hidden;
        width: 56px;
        height: 56px;
    }


    .cBtnOn {
        background-image: url({MODULE_URL}images/sprNewBg.png);
        background-position: -22px 0;
    }
    .cBtn {
        right: -10px;
        top: -10px;
    }

    .cBtn {
        width: 22px;
        height: 22px;
        background: url({MODULE_URL}images/sprNewBg.png) no-repeat;
        background-size: 316px auto;
        -webkit-background-size: 316px auto;
        font-size: 0;
    }

    .pa {
        position: absolute;
    }
    .db {
        display: block;
    }

</style>
<input type="hidden" id="image" name="image" value="" />

<ul class="uploadimg">

    <li class="upload_btn" style="height: 72px;">
        <input type="button" id="chooseImage" />
    </li>
    <div style="clear: both;"></div>
</ul>
<script>
    // 5 图片接口
    // 5.1 拍照、本地选图
    var images = {
        localId: [],
        serverId: []
    };

    var height = $(window).width() * 0.22;

    $('.upload_btn').height(height);

    document.querySelector('#chooseImage').onclick = function () {
        wx.chooseImage({
            success: function (res) {
                images.localId = res.localIds;
                //alert('已选择 ' + res.localIds.length + ' 张图片');
                var ss = images.localId;
                for (var i = 0; i < ss.length; i++) {
                    a = $('<a href="javascript:;" class="cBtn cBtnOn pa db" title="">关闭</a>');
                    $li = $("<li><img src='" + ss[i] + "' style='height:" + height + "px'</li>");
                    a.click(function () {
                        images.serverId.splice($(this).parent().index(), 1);
                        $(this).parent().remove();
                    });
                    $li.append(a);
                    $('.uploadimg li.upload_btn').before($li);
                }
                uploadImg();
            }
        });
    };

    // 5.3 上传图片
    function uploadImg() {
        if (images.localId.length == 0) {
            alert('无任何图片。');
            return;
        }

        if (images.localId.length > 9) {
            alert('图片不能超过九张，请删除多余的图片。');
            return;
        }
        var i = 0, length = images.localId.length;
        //serverId = [];
        function upload() {
            wx.uploadImage({
                localId: images.localId[i],
                isShowProgressTips: 1, // 默认为1，显示进度提示-
                success: function (res) {
                    i++;
                    //alert('已上传：' + i + '/' + length);
                    images.serverId.push(res.serverId);
                    if (i < length) {
                        upload();
                    } else {
                    }
                },
                fail: function (res) {
                    alert(JSON.stringify(res));
                }
            });
        }

        upload();
    };


       
    
    
</script>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">商家电话</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[phone]" class="form-control" value="{$business['phone']}" />						
					</div>
				</div>				
				<script type="text/javascript">
					require(['industry'], function(industry){
						industry.init('industry_1','industry_2');
					});
				</script>						
				
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">网址</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[net]" class="form-control" value="{$business['net']}" />						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">地址</label>
					<div class="col-xs-12 col-sm-8">
					<input type="text" name="business[address]" id="address" class="form-control" value="{$business['address']}" />	
					<span class="input-group-addon">地址可以不用填写，获取定位时候自动添加</span>					
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">地图</label>
					<div class="col-xs-6 col-sm-2">
					<input type="text" name="business[lng]" class="form-control"  id="lng" value="{$business['lng']}" />
					</div>
					<div class="col-xs-6 col-sm-2">
					<input type="text" name="business[lat]" class="form-control"  id="lat" value="{$business['lat']}" />		
					</div>
				</div>
					<div class="form-group">
<div class="col-xs-12 col-sm-2">
					<div type="button" class="btn btn-default btn-block" data-toggle="modal" data-target="#myModal">
					  点击选择定位坐标
					</div>
					</div>

					<!-- Modal -->
					<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
					  <div class="modal-dialog" role="document">
						<div class="modal-content">
						  <div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">地图选择</h4>
						  </div>
						  <div class="modal-body">
						   <iframe id="iframe" width="100%" height="500" frameborder=0 
						src="http://apis.map.qq.com/tools/locpicker?search=1&type=1&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&referer=myapp">
					</iframe> 
					 
					<script>
							//iframe页面调用方法
							$(function(){ 

								adaptHeight();//动态适配高度
							   
								window.onresize = function() { //横屏、QQ浏览器变全屏模式下的时候，需要重新计算高度              
									adaptHeight();                
								}

								window.addEventListener('message', function(event) {
									var loc = event.data;
									document.getElementById("lng").value=loc.latlng.lat;
									document.getElementById("lat").value=loc.latlng.lng;
									document.getElementById("address").value=loc.poiaddress;
									$(".close").click();
								}, false);

								function adaptHeight() {
									var winH = $(window).height(); 
									var bodyH = document.documentElement.clientHeight; 
									if (winH > bodyH) {
										window.parent.document.getElementById("iframe").height=winH;
									} else {
										window.parent.document.getElementById("iframe").height=bodyH;
									}  
								}
							});
						</script>
						  </div>						 
						</div>
					  </div>
					</div>									
											
					</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">主营</label>
					<div class="col-xs-12 col-sm-8">
						<textarea  name="business[zy]" class="form-control">{$business['zy']}</textarea>						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">简介</label>
					<div class="col-xs-12 col-sm-8">
						<textarea  name="business[desc]" class="form-control">{$business['desc']}</textarea>						
					</div>
				</div>				
				{if !empty($id)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">添加日期</label>
					<div class="col-xs-12 col-sm-8">
						<p class="form-control-static">{php echo date('Y-m-d H:s:i', $business['time']);}</p>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">到期日期</label>
					<div class="col-xs-12 col-sm-8">
						<p class="form-control-static">{php echo date('Y-m-d H:s:i', strtotime ("+1 year", strtotime(date('Y-m-d H:s:i', $business['time']))))}</p>
					</div>
				</div>
				{/if}
				<div class="weui_cells weui_cells_checkbox">
            <label for="s11" class="weui_cell weui_check_label">
               
                <div class="weui_cell_bd weui_cell_primary">
					{if $business['pay'] == 1}
					<p>已支付</p>
					{else}
                    <p>微信支付{$settings['feiyong']}元</p>
					{/if}
                </div>
                 <div class="weui_cell_hd">
                    <input type="checkbox" checked="checked" id="s11" name="checkbox1" class="weui_check">
                    <i class="weui_icon_checked"></i>
                </div>
            </label>
                    
                      
        </div>
				<div class="form-group">
					<div class="col-xs-12 col-sm-8">						
						<input name="submit" type="submit" value="提交" class="weui_btn weui_btn_primary" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
 
<script>
require(['jquery', 'util'], function($, util){
	$(function(){
		$('#form').submit(function(){			
			if($('input[name="business[weixin]"]').val() == ''){
				util.message('请填写您的微信号.');
				return false;
			}
			if($('input[name="business[name]"]').val() == ''){
				util.message('请填写商家名称.');
				return false;
			}			
			if($('input[name="business[logo]"]').val() == ''){
				util.message('请上传商家外观照片.');
				return false;
			}
			if($('input[name="business[phone]"]').val() == ''){
				util.message('请填写商家电话.');
				return false;
			}	
			$('#image').val(images.serverId);					
			return true;
		});
	});
});
</script>
{/if}

{if $op == 'weixin'}
	<form action="" method="post" class="form-horizontal form" id="form" style="padding-bottom:55px">
		<div class="panel panel-default">
		<div class="panel-heading">个人信息</div>
		<div class="panel-body">
		<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">微信号</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[weixin]" class="form-control" value="{$business['weixin']}" />						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">选择性别</label>
					<div class="col-xs-12 col-sm-8">
						<select class="form-control" name="business[sex]">
					
					  <option value="1">男神</option>
					  <option value="2">女神</option>
					 
				</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">个人一句话介绍</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[yjh]" class="form-control" value="{$business['yjh']}" />						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">头像</label>
					<div class="col-xs-12 col-sm-8">
						{php echo tpl_form_field_image('business[avatar]', $business['avatar']);}
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">二维码</label>
					<div class="col-xs-12 col-sm-8">
						{php echo tpl_form_field_image('business[ewm]', $business['ewm']);}
					</div>
				</div>
				
				
			</div>
			
			<div class="panel-body">
				{if !empty($id)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">添加日期</label>
					<div class="col-xs-12 col-sm-8">
						<p class="form-control-static">{php echo date('Y-m-d H:s:i', $business['time']);}</p>
					</div>
				</div>
				
				{/if}
			
                    
                      
        </div>
				<div class="form-group">
					<div class="col-xs-12 col-sm-8">						
						<input name="submit" type="submit" value="提交" class="weui_btn weui_btn_primary" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
 
<script>
require(['jquery', 'util'], function($, util){
	$(function(){
		$('#form').submit(function(){			
			if($('input[name="business[weixin]"]').val() == ''){
				util.message('请填写您的微信号.');
				return false;
			}
			
							
			return true;
		});
	});
});
</script>
{/if}
{template 'common/footer'}
{template 'footer'}